package task3.save;

import java.security.InvalidParameterException;
import javax.media.jai.JAI;
import task3.pimpmypipe.DataTransformationFilter;
import task3.util.FilterObservable;
import task3.util.ImageTO;

public class SaveFilter
  extends DataTransformationFilter<ImageTO>
{
  private String _fileName;
  private FilterObservable _observable;
  
  public SaveFilter()
    throws InvalidParameterException
  {
    this._observable = new FilterObservable();
    this._fileName = "Filename";
  }
  
  protected void process(ImageTO entity)
  {
    JAI.create("filestore", entity.getEditedImage(), this._fileName + ".jpg", "JPEG");
    
    this._observable.setChanged();
    this._observable.notifyObservers(entity);
  }
  
  public String getFileName()
  {
    return this._fileName;
  }
  
  public void setFileName(String fileName)
  {
    this._fileName = fileName;
  }
  
  public FilterObservable getObservable()
  {
    return this._observable;
  }
}
